package com.inspur.base;

import com.mangofactory.swagger.configuration.SpringSwaggerConfig;
import com.mangofactory.swagger.models.dto.ApiInfo;
import com.mangofactory.swagger.plugin.EnableSwagger;
import com.mangofactory.swagger.plugin.SwaggerSpringMvcPlugin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
/**
 * 
 * fangw@2017-1-16：自定义Swagger的配置类.
 * 
 * <pre>
 * fangw@2017-1-16：自定义Swagger的配置类。
 * </pre>
 * 
 * @author fangw
 *
 */
@Configuration  
@EnableWebMvc  
@EnableSwagger  
@ComponentScan(basePackages ={"com.inspur.controller"})
public class SwaggerConfig {
    private SpringSwaggerConfig springSwaggerConfig;
    @Autowired
    public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig)
    {
        this.springSwaggerConfig = springSwaggerConfig;
    }

    /**
     * Every SwaggerSpringMvcPlugin bean is picked up by the swagger-mvc
     * framework - allowing for multiple swagger groups i.e. same code base
     * multiple swagger resource listings.
     */
    @Bean
    public SwaggerSpringMvcPlugin customImplementation()
    {
        return new SwaggerSpringMvcPlugin(this.springSwaggerConfig)
                .apiInfo(apiInfo())
                .includePatterns(".*?");
    }

    private ApiInfo apiInfo()
    {
        ApiInfo apiInfo = new ApiInfo(
                "国网portal接口",
                "国网portal接口列表，可用于查看和在线测试",
                "My Apps API terms of service",
                "fangw@inspur.com",
                "My Apps API Licence Type",
                "My Apps API License URL");
        return apiInfo;
    }
}
